package com.yuda.campsite.controller;

import com.alibaba.fastjson.JSONObject;
import com.yuda.campsite.domain.NewStudnet;
import com.yuda.campsite.domain.ShouHuoDiZhi;
import com.yuda.campsite.domain.ZhengShuGuanLi;
import com.yuda.campsite.dto.ShouHuoDiZhiParam;
import com.yuda.campsite.service.ShouHuoDiZhiService;
import com.yuda.common.core.utils.poi.ExcelUtil;
import com.yuda.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author: xiaohudie
 * @Date: 2022/2/9 17:04
 * @Version: 1.8
 */
@RestController
@RequestMapping("/ShouHuoDiZhi")
public class ShouHuoDiZhiController {
     @Resource
     private ShouHuoDiZhiService shouHuoDiZhiService;
     /**查看收货地址列表*/
     @GetMapping("/LieBiao")
    public String LieBiao(ShouHuoDiZhiParam shouHuoDiZhiParam){
         Integer a =(shouHuoDiZhiParam.getQisi()-1)*shouHuoDiZhiParam.getOffset();
         shouHuoDiZhiParam.setQisi(a);
         List<ShouHuoDiZhi> shouHuoDiZhis = shouHuoDiZhiService.ShouHuoDiZhiLieBiao(shouHuoDiZhiParam);
         for (ShouHuoDiZhi shouHuoDiZhi : shouHuoDiZhis) {
             if (shouHuoDiZhi.getIsXueXiBiaoBing()!=null && shouHuoDiZhi.getIsXueXiBiaoBing().equals("0")){
                 shouHuoDiZhi.setIsXueXiBiaoBing("否");
             }
             if (shouHuoDiZhi.getIsXueXiBiaoBing()!=null && shouHuoDiZhi.getIsXueXiBiaoBing().equals("1")){
                 shouHuoDiZhi.setIsXueXiBiaoBing("是");
             }
             if (shouHuoDiZhi.getXueXiChengGuo()!=null && shouHuoDiZhi.getXueXiChengGuo().equals("0")){
                 shouHuoDiZhi.setXueXiChengGuo("否");
             }
             if (shouHuoDiZhi.getXueXiChengGuo()!=null && shouHuoDiZhi.getXueXiChengGuo().equals("1")){
                 shouHuoDiZhi.setXueXiChengGuo("是");
             }
         }
         shouHuoDiZhiParam.setQisi(0);
         shouHuoDiZhiParam.setOffset(10000);
         List<ShouHuoDiZhi> shouHuoDiZhis1 = shouHuoDiZhiService.ShouHuoDiZhiLieBiao(shouHuoDiZhiParam);
         JSONObject jsonObject =new JSONObject();
         jsonObject.put("message","请求成功");
         jsonObject.put("code",200);
         jsonObject.put("total",shouHuoDiZhis1.size());
         jsonObject.put("data",shouHuoDiZhis);
         return jsonObject.toJSONString();
     }
     /**查看学生的收货地址*/
     @GetMapping("/ChaKan")
     public AjaxResult ChaKan(ShouHuoDiZhiParam shouHuoDiZhiParam){
         ShouHuoDiZhi shouHuoDiZhi = shouHuoDiZhiService.ShouHuoDiZhiChaKan(shouHuoDiZhiParam);
        return AjaxResult.success("查看成功",shouHuoDiZhi);
     }
     /**修改学生的收货地址*/
     @PostMapping("XiuGai")
    public AjaxResult XiuGai(ShouHuoDiZhiParam shouHuoDiZhiParam){
         shouHuoDiZhiService.ShouHuoDiZhiXiuGai(shouHuoDiZhiParam);
         return AjaxResult.success("修改成功");
     }
     /**导表数据*/
     @PostMapping("/DaoBiao")
    public void DaoBiao(ShouHuoDiZhiParam shouHuoDiZhiParam, HttpServletResponse response) throws IOException {
         List<ShouHuoDiZhi> shouHuoDiZhis = shouHuoDiZhiService.DaoBiaoChaXun(shouHuoDiZhiParam);
         for (ShouHuoDiZhi shouHuoDiZhi : shouHuoDiZhis) {
             shouHuoDiZhi.setShuohuoDizhi(shouHuoDiZhi.getCertificateProvince()+shouHuoDiZhi.getCertificateCity()+shouHuoDiZhi.getCertificateAddress());
         }
             ExcelUtil<ShouHuoDiZhi> util = new ExcelUtil<ShouHuoDiZhi>(ShouHuoDiZhi.class);
             util.exportExcel(response,shouHuoDiZhis , "conf");
         }

}
